Project Name: Kad Keputusan (Decision Card)
Inspired By: Saidina / Monopoly
What is it? This project is a simple, standalone fortune teller for your game nights! Press the button, and the ESP32 randomly draws a Chance or Community Chest card, displaying the outcome with lights and sounds—will you win a prize or pay a fine?
What Will You Learn
- Use Digital Cards: Store different messages and outcomes (positive/negative) using a programming structure called a
struct. - Create Randomness: Use the ESP32 to randomly choose which card set (Chance or Community Chest) and which card to draw.
- Give Instant Feedback: Use Green and Red LEDs to immediately show if the news is good or bad.
- Add Sound Effects: Use a buzzer to play triumphant sounds for good luck and a warning for bad luck!
- Master the LCD: Display the card results clearly on the small screen.
Circuit Connections
This map shows you the physical map for building the project. It shows exactly where to plug in every wire for the buttons, LEDs, and screen so that the software instructions can correctly control all the hardware pieces.

| Components | ESP32 Dev Module | The Functions |
| LCD I2C SDA/SCL | SDA/SCL | The Card Display! Shows the card set and the outcome. |
| BUZZER | IO25 | The Draw! You press this single button to draw a random card. |
| GREEN LED | IO27 | Good News Light! Flashes ON if the card outcome is positive. |
| RED LED | IO26 | Bad News Light! Flashes ON if the card outcome is negative (a fine or tax). |
| PUSH BUTTON | IO12 | The Announcer! Plays happy sounds for wins and sad sounds for losses. |
Logic Flow

Code Lab

This section holds the instructions for the ESP32. It’s the “brain” that tells the board exactly what to do, like when to flash a green light, what sound to play, and how to choose a random card. You copy and upload this code so your project can actually work.
Step 1: Install Library
Before uploading the code, you need to install these libraries in Arduino IDE:
- LiquidCrystal_I2C.h by Frank de Brabander (for I2C LCD)
For example:

Step 2: Code
Copy and paste this code into Arduino IDE:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD I2C address
const int buttonPin = 12;
const int greenLED = 27;
const int redLED = 26;
const int buzzer = 25;
struct Card {
String message;
bool isPositive;
};
Card communityChestCards[] = {
{"Win prize 100", true},
{"Pay tax 200", false},
{"Scholarship 150", true},
{"Fine 100", false}
};
Card chanceCards[] = {
{"Go to jail", false},
{"Lottery 200", true},
{"Insurance 100", false},
{"Sell stock 150", true}
};
int totalCommunity = sizeof(communityChestCards) / sizeof(communityChestCards[0]);
int totalChance = sizeof(chanceCards) / sizeof(chanceCards[0]);
bool buttonPressed = false;
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.init();
lcd.backlight();
showDefaultMessage();
}
void loop() {
if (digitalRead(buttonPin) == LOW && !buttonPressed) {
buttonPressed = true;
drawRandomCard();
delay(3000); // Show message for 3 seconds
showDefaultMessage();
}
if (digitalRead(buttonPin) == HIGH) {
buttonPressed = false; // Ready for next press
}
}
void showDefaultMessage() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Decision Card ");
lcd.setCursor(0, 1);
lcd.print(" Press Button ");
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
noTone(buzzer);
}
void drawRandomCard() {
lcd.clear();
bool isCommunity = random(0, 2); // 0 = Chance, 1 = Community Chest
Card selectedCard;
if (isCommunity) {
int i = random(totalCommunity);
selectedCard = communityChestCards[i];
lcd.setCursor(0, 0);
lcd.print("Community Chest");
} else {
int i = random(totalChance);
selectedCard = chanceCards[i];
lcd.setCursor(0, 0);
lcd.print("Chance");
}
lcd.setCursor(0, 1);
lcd.print(selectedCard.message);
if (selectedCard.isPositive) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
// Play positive sound
tone(buzzer, 1000, 200); delay(200);
tone(buzzer, 1500, 200); delay(200);
tone(buzzer, 2000, 300);
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
// Play error sound
tone(buzzer, 300, 400); delay(500);
tone(buzzer, 200, 600);
}
}
Step 3: Upload and Run
- Connect your ESP32 board
- Upload the code
- Open Serial Monitor at 115200 baud
How to Play

Using the Kad Keputusan is super easy, it;s all about the button!
- Ready Screen
When you turn on the project, the LCD will display the waiting meesage:
Decision Card
Press Button
The Green and Red LEDs should both be OFF.
2. Drawing a Card
- Press the Button (GPIO12): Whenever you need a card outcome in your game (like landing on a Chance space), press the single decision button.
- The Reveal: The screen instantly clears and reveals the result.
- Line 1: Shows which deck was drawn: “Community Chest” or “Chance”.
- Line 2: Shows the card’s message (e.g., “Lottery 200”).
3. Instant Outcome!
The lights and sounds tell you the card’s fortune immediately:
| Outcome | LED | Sound | Message Example |
| POSITIVE (Good News!) | GREEN LED is ON | Plays a happy, high-pitched ascending tone (a win!). | “Win prize 100” |
| NEGATIVE (Bad News!) | RED LED is ON | Plays a low, sad descending error tone (a fine!) | “Pay tax 200” |
4. Get Ready for the Next Draw
The card message stays on the screen for 3 seconds. After that, the screen clears, the LEDs turn OFF, and the default “Press Button” message returns, ready for the next player!
Troubleshooting Guide
This guide is your fast-fix manual for when errors occur. It helps you quickly diagnose why something isn’t working, like a dark screen or a silent buzzer—and provides simple steps to correct the problem.
| Problem | What is Happening? | Simple Solution to Try |
| The screen is dark or shows black boxes | The LCD is missing its settings or needs a contrast | 1. Check Wires: Double check SDA and SCL. 2. Adjust knob: Gently turn the small screw on the back of the screen |
| The button doesn’t draw a card | The ESP32 can’t detect the button | Make sure wire goes to GPIO12 |
| The LEDs are on the wrong pin or won’t light up | The lights are weird backward | Make sure to connect the wire to correct GPIO pin |
| The buzzer is silent | The speaker is not connected correctly | Make sure the wire correctly wired to GPIO25 |
Buy from:
Myduino AIoT Education Kit from myduino.com






